﻿using System;
using System.Configuration;
using Koonsoft.HYCRM.BLL;
using log4net;

public partial class Order_BuildOrder : System.Web.UI.Page
{
    private ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Request.QueryString["cacheId"] != null)
            {
                CacheID.Value = Request.QueryString["cacheId"];

                string orderID = string.Empty;
                string msg = string.Empty;

                var order = ObjectCacheHelper.GetObjectCache<OrderInfo>(CacheID.Value);

                if (order != null)
                {
                    var orderService = new OrderService();
                    orderService.Url = ConfigurationManager.AppSettings["OrderServiceURL"];

                    if (orderService.CreateOrder(order, out orderID, out msg))
                    {
                        if (!string.IsNullOrEmpty(orderID))
                        {
                            Label1.Text = string.Format("订单生成成功,单号 {0} ", orderID);
                        }
                    }
                    else
                    {
                        Label1.Text = string.Format("订单生成失败,原因 {0} ", msg);
                    }
                }
                else
                {
                    logger.Warn(string.Format("通过GUID获取订单缓存信息出错，GUID'{0}'", CacheID.Value));
                }
            }

        }
        catch (Exception ex)
        {
            logger.Error("订单生成异常", ex);
        }
    }

    protected void Continue_Click(object sender, EventArgs e)
    {
        Response.Redirect("MakeOrder.aspx");
    }
}